<?php

require_once('lib_load.php');
load_lib(array('DbMysql', 'User'));

$user = new User();

$user->Refresh(); //security check

// List of groups
$db->Query('SELECT id, name FROM player WHERE user = \''.$user->GetLogin().'\'');

$shadows = $db->Query2Array();

// first time
if (empty($shadows))
    header("Location: crshadow.php");
// else
foreach($shadows as $column=>$value)
    @$buf_list .= 'Shadow name: <a href="shadows.php?log='.$value['id'].'">'.$value['name'].'</a><br />';//onClick="javascript:window.open(\'shadows.php?log='.$value['id'].'\',\'Lane\',\'width='.((($user->GetXMap()*2)+1)*32).',height='.((($user->GetYMap()*2)+1)*32).',toolbar=no,location = no, resizable = no, scrollbars = no, status = no\');">'.$value['name'].'</a><br />';

// Loging shadow in
if (isset($_GET['log']))
{
    if ($db->IsExist('player', '(id = \''.mysql_real_escape_string($_GET['log']).'\') && (user = \''.$user->GetLogin().'\')'))
    {
        $db->UpdateData('users', array('chosen_shadow' => intval($_GET['log'])), 'login = \''.$user->GetLogin().'\'');
        header('Location: main.php');
    }
}

// Loadfing the infomation in main_buffer
$main_buf = implode('',file('templates/index.htm'));
$reg_buf = implode('',file('templates/data/shadow/index.htm')).$buf_list.'<br /> <a href="crshadow.php">Create a new shadow.</a>';
$main_buf=str_replace("[%INFO%]",$reg_buf ,$main_buf);

// main info output
echo $main_buf;
?>
